﻿using EFCore.Core.Models;
using EFCore.Injector;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Yookey.GSFJCSZF.IRepository;
using Yookey.GSFJCSZF.IService;
using Yookey.GSFJCSZF.Models;

namespace Yookey.GSFJCSZF.Service
{
    public class DemoService : IDemoService, ITransientDependency
    {
        public IDemoRepository _demoRepository { get; set; }
        public async Task<BaseResponse<Demos>> GetDemo()
        {
            BaseResponse<Demos> _baseGetResponse = new BaseResponse<Demos>();
            try
            {
                var rs =await _demoRepository.SelectSingle();
                if (rs !=null)
                {
                    _baseGetResponse.Data = rs;
                    _baseGetResponse.Message = "获取成功";
                }
            }
            catch (Exception ex)
            {
                _baseGetResponse.Message = ex.Message;
                _baseGetResponse.Code = ResultCode.UnknownException;
            }
            return _baseGetResponse;
        }

        public async Task<BaseResponse<List<Demos>>> GetDemosByTitle(string keywords)
        {
            BaseResponse<List<Demos>> _baseGetResponse = new BaseResponse<List<Demos>>();
            if (string.IsNullOrEmpty(keywords))
            {
                _baseGetResponse.Code = ResultCode.ParametersRequired;
                _baseGetResponse.Message = "关键词不能为空";
                return _baseGetResponse;
            }
            try
            {
                var rs = await _demoRepository.SelectList(keywords);
                if (rs != null)
                {
                    
                    _baseGetResponse.Data = rs;
                    _baseGetResponse.Message = "获取成功";
                }
            }
            catch (Exception ex)
            {
                _baseGetResponse.Message = ex.Message;
                _baseGetResponse.Code = ResultCode.UnknownException;
            }
            return _baseGetResponse;
        }
    }
}
